﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;


using System.Security.Cryptography;
using System.Text;
using EnvironmentManagerSystem.smss;




using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;


namespace EnvironmentManagerSystem.DX
{
    public partial class DX : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        string sn = "SDK-HYL-010-00026";//序列号
        string password = "976136";//密码
        //string mobile = "13359992420";//手机
        string mobile = "13359992420,18686853420";//手机
        string cont = "测试发送短信";//内容
        string subcode = "";//扩展码
        string stime = "";//定时时间

        //sms.WebService sms = new newWebservice_simple.sms.WebService();

        //ServiceReference1 sms = new EnvironmentManagerSystem.ServiceReference1();
        smss.WebService sms = new EnvironmentManagerSystem.smss.WebService();
       //sms.WebService sms = new EnvironmentManagerSystem.sms.WebService();
        
        #region MyRegion
        /// <summary>
        /// 获取参数
        /// </summary>
        private void getValues()
        {
            mobile = tex_mobile.Text;
            //subcode = tex_subcode.Text;
            //if (sch_time.Enabled)
            //{
            //    //取得定时时间
            //    stime = sch_time.Text;
            //}
            cont = rich_content.Text;
        }
        /// <summary>
        /// 获取md5码
        /// </summary>
        /// <param name="source">待转换字符串</param>
        /// <returns>md5加密后的字符串</returns>
        public string getMD5(string source)
        {
            string result = "";
            try
            {
                MD5 getmd5 = new MD5CryptoServiceProvider();
                byte[] targetStr = getmd5.ComputeHash(UnicodeEncoding.UTF8.GetBytes(source));
                result = BitConverter.ToString(targetStr).Replace("-", "");
                return result;
            }
            catch (Exception)
            {
                return "0";
            }

        }
        #endregion
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Start_Click(object sender, EventArgs e)
        {
            //获取参数
            getValues();
            //MD5加密密码
            string pwd = getMD5(sn + password);



            long startTime, endTime;
            startTime = DateTime.Now.Ticks;//记录当前时刻

            //发送短信
            //定时时间，扩展码和rrid可以为空，当rrid(唯一标识串)为空时，返回系统指定rrid
            string result = sms.mt(sn, pwd, mobile, cont, subcode, stime, "");

            endTime = DateTime.Now.Ticks;
            TimeSpan sendSpan = new TimeSpan(endTime - startTime);
            if (result.StartsWith("-"))
            {
                rich_output.Text += result + "\r";
                //rich_output.AppendText(result + "\r");
                //rich_output.Refresh();
                
            }
            else
            {
                //rich_output.AppendText("发送成功" + "\r");
                rich_output.Text += "发送成功" + "\r";
                //rich_output.AppendText("发送用时" + sendSpan.ToString() + "s\r");
                rich_output.Text += "发送用时" + sendSpan.ToString() + "s\r";
                //rich_output.Refresh();
            }
        }
    }
}
